﻿using System.Windows;
using System.Windows.Controls;
using JY.Wpf.TestForMetro.ViewModels.MVVMDemoViewModels;

namespace JY.Wpf.TestForMetro.Selector
{
    /// <summary>
    /// 测试表单模板选择器
    /// </summary>
    public class TestFormTemplateSelector : DataTemplateSelector
    {
        /// <summary>
        /// 文本
        /// </summary>
        public DataTemplate TextDataTemplate { get; set; }
        /// <summary>
        /// 数字
        /// </summary>
        public DataTemplate NumberDataTemplate { get; set; }
        /// <summary>
        /// 单选
        /// </summary>
        public DataTemplate RadioDataTemplate { get; set; }
        /// <summary>
        /// 下拉列表
        /// </summary>
        public DataTemplate ComboBoxTemplate { get; set; }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            if (!(item is FormItem testFormItem)) return base.SelectTemplate(item, container);
            switch (testFormItem.FormValueType)
            {
                case FormValueType.文本:
                    return this.TextDataTemplate;
                case FormValueType.数字:
                    return this.NumberDataTemplate;
                case FormValueType.单选:
                    return this.RadioDataTemplate;
                case FormValueType.下拉列表:
                    return this.ComboBoxTemplate;
            }
            return base.SelectTemplate(item, container);
        }
    }
}
